package cn.tianyigps.tianyigpsyndistributetask.dao;

import cn.tianyigps.tianyigpspublic.bean.EquipmentConfig;
import cn.tianyigps.tianyigpspublic.bean.EquipmentLastData;
import cn.tianyigps.tianyigpspublic.param.constant.CollectionNameConstant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Repository;
import org.springframework.util.CollectionUtils;

import java.util.List;

/**
 * @Author: WEI.YUAN
 * @Descirption:
 * @Date: 2019/4/26_19:25
 */
@Repository
public class DistributeTaskDaoImpl implements DistributeTaskDao {
    @Autowired
    MongoTemplate mongoTemplate;

    @Override
    public void insertEquipmentConfig(EquipmentConfig equipmentConfig) {
        mongoTemplate.insert(equipmentConfig, CollectionNameConstant.EQUIPMENT_CONFIG);
    }

    @Override
    public EquipmentConfig getEquipmentConfigById(String equipmengId) {
        Query query = new Query(Criteria.where("equipmentId").is(equipmengId));
        List<EquipmentConfig> eqConfig = mongoTemplate.find(query, EquipmentConfig.class, CollectionNameConstant.EQUIPMENT_CONFIG);
        EquipmentConfig eqmodel = null;
        if (!CollectionUtils.isEmpty(eqConfig)) {
            eqmodel = eqConfig.get(0);
        }
        return eqmodel;
    }
}
